package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class JDBCDemo11 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection()){
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入用户名：");
            String username = sc.next();
            System.out.println("请输入新密码：");
            String password = sc.next();
            System.out.println("请输入新昵称：");
            String nickname = sc.next();
            String sql = "UPDATE userinfo SET password=? AND nickname=? WHERE username=?";
            PreparedStatement statement = connection.prepareStatement(sql);
            statement.setString(1, password);
            statement.setString(2, nickname);
            statement.setString(3, username);
            int count = statement.executeUpdate();
            System.out.println(count>0?"注册成功！":"注册失败！");

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
